package com.bingxue.edu.config;

import com.bingxue.edu.common.config.EducationProperties;
import com.bingxue.edu.common.config.NotifyConfigProperties;
import com.bingxue.edu.common.config.WechatProperties;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.LocalDateTime;
import java.util.LinkedHashMap;

import static com.bingxue.edu.common.constant.DateConstants.FORMATTER_TIME_HHmm_CN;

/**
 * @author panbo
 * @since 2024/12/18
 */
@SpringBootTest
class ConfigLoadTest {

    @Autowired
    private NotifyConfigProperties notifyConfigProperties;

    @Autowired
    private WechatProperties wechatProperties;

    @Autowired
    private EducationProperties educationProperties;

    @Autowired
    private WxCpService wxCpService;

//    @Test
    public void test() {
        System.out.println("config: " + educationProperties);
    }


//    @Test
    public void testSendWxCpMessage() {
        try {
            WxCpMessage wxCpMessage = new WxCpMessage();
            wxCpMessage.setSafe("0");
            wxCpMessage.setMsgType(WxConsts.KefuMsgType.MINIPROGRAM_NOTICE);
            wxCpMessage.setToUser("PanBo|XingKong");
            wxCpMessage.setAppId(wechatProperties.getEmployeeAppId());
            wxCpMessage.setPage("pages/class/detail?id=2025Q1492422");
            wxCpMessage.setTitle("学生报名成功通知");
            wxCpMessage.setDescription(LocalDateTime.now().format(FORMATTER_TIME_HHmm_CN));
            LinkedHashMap<String, String> items = new LinkedHashMap<>();
            items.put("学生", "张二娃");
            items.put("联系方式", "13577899876");
            items.put("报名班级", "2025春季四年级小学思维好学B(周五18:30-21:00)");
            items.put("报名课次", "4节");
            items.put("班级名额", "3/16");
            wxCpMessage.setContentItems(items);
            wxCpMessage.setEmphasisFirstItem(true);

            wxCpService.getMessageService().send(wxCpMessage);
        } catch (Exception e) {
            System.out.println("发送错误");
        }

    }
}

